/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.actionlisteners;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import javax.swing.BorderFactory;
import project.jpdftools.ui.logic.JPDFText;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;

/**
 *
 * @author Mido
 */
public class ShowBorderAction implements ActionListener {

    private Object component;

    public ShowBorderAction(Object component) {
        super();
        this.component = component;
    }

    public void actionPerformed(ActionEvent evt) {
        if (component instanceof JPDFText) {
            JPDFText text = (JPDFText) component;
            if (text.isShowBorder() == false) {
                // show border
                if (text.getBorderColor() == null) {
                    // default border color
                    text.getScrollPane().setBorder(BorderFactory.createLineBorder(Color.black));
                    text.setShowBorder(true);
                    // change button name
                    text.getMiShowBorder().setText(LocalizationManager.getCurrent_resource().getString("JPDFTEXT_HIDE_BORDER"));
                    LoggerManager.getLogger().log(Level.INFO, "Default border used. Component ID = {0}", text.getId());
                } else {
                    // use component border color
                    text.getScrollPane().setBorder(BorderFactory.createLineBorder(text.getBorderColor()));
                    text.setShowBorder(true);
                    // change button name
                    text.getMiShowBorder().setText(LocalizationManager.getCurrent_resource().getString("JPDFTEXT_HIDE_BORDER"));
                    LoggerManager.getLogger().log(Level.INFO, "Component border applied. Component ID = {0}", text.getId());
                }
            } else {
                // hide border
                text.getScrollPane().setBorder(null);
                text.setShowBorder(false);
                // change button name
                text.getMiShowBorder().setText(LocalizationManager.getCurrent_resource().getString("JPDFTEXT_SHOW_BORDER"));
                LoggerManager.getLogger().log(Level.INFO, "Component border hidden. Component ID = {0}", text.getId());
            }
        }
    }
}
